<template>
  <div>
    <Form :validOnChange="true" :model="httpModel">
      <FormItem label="请求地址">
        <input type="text" v-model="httpModel.url" />
      </FormItem>
      <FormItem label="上传名称"  v-show="nodeType == 'HTTP_UPLOAD'">
        <input type="text" v-model="httpModel.name" />
      </FormItem>
      <FormItem label="数据类型" v-show="nodeType != 'HTTP_UPLOAD'">
        <AutoComplete :must-match="false" :option="param" :datas="contentTypeData" v-model="httpModel.contentType" type="title"></AutoComplete>
      </FormItem>
      <FormItem label="请求方式" v-show="nodeType != 'HTTP_UPLOAD'">
        <AutoComplete :must-match="false" :option="param" :datas="methodData" v-model="httpModel.method" type="title"></AutoComplete>
      </FormItem>
      <FormItem label="成功条件">
        <input v-model="httpModel.success" type="text" />
      </FormItem>
      <FormItem label="数据域名">
        <input v-model="httpModel.dataKey" type="text" />
      </FormItem>
      <FormItem label="响应格式">
        <Select :datas="dataType" v-model="httpModel.dataType"></Select>
      </FormItem>
    </Form>
    <div slot="footer">
      <Button :block="true" text-color="primary" @click="save">确认</Button>
    </div>
    <br />
    <Row v-show="nodeType == 'HTTP_UPLOAD'">
      <div>
        <div class="text-left bottom-line" style="font-size:8px;padding:5px;" v-show="nodeType == 'HTTP_UPLOAD'">
          <span class="primary-color">sourceFile</span>&nbsp;&nbsp;<span>文件来源，本地上传时开始节点生成sourceFile参数数据</span>
        </div>
      </div>
    </Row>
  </div>
</template>
<script>
export default {
  data() {
    return {
      nodeType: "",
      methodData: [
        { keyId: "GET", title: "GET" },
        { keyId: "POST", title: "POST" },
        { keyId: "PUT", title: "PUT" },
        { keyId: "DELETE", title: "DELETE" },
      ],
      dataType: [
        { keyId: "list", title: "JSON集合" },
        { keyId: "object", title: "JSON对象" },
        { keyId: "string", title: "字符文本" },
        { keyId: "bytes", title: "文件流" },
      ],
      contentTypeData: [
        {
          keyId: "application/json;charset=utf-8",
          title: "application/json;charset=utf-8",
        },
        { keyId: "multipart/form-data", title: "multipart/form-data" },
        {
          keyId: "application/octet-stream",
          title: "application/octet-stream",
        },
        { keyId: "text/html", title: "text/html" },
        { keyId: "text/plain", title: "text/plain" },
      ],
      httpModel: {
        url: "",
        contentType: "",
        method: "",
        success: "code == 0000",
        dataKey: "data",
        dataType: "list",
      },
      param: {
        keyName: "keyId",
        titleName: "title",
      },
    };
  },
  methods: {
    httpInit(data, nodeType) {
      if (!!data) {
        this.httpModel = data;
        this.nodeType = nodeType;
      }
    },
    save() {
      this.$emit("setContent", this.httpModel);
    },
  },
  deactivated() {
    this.$destroy(true);
  },
};
</script>
